package com.xll.controller;

import com.xll.entity.Hotel;
import com.xll.entity.Order;
import com.xll.entity.Remark;
import com.xll.service.HotelService;
import com.xll.service.OrderService;
import com.xll.service.RemarkService;
import com.xll.utils.QueryInfo;
import com.xll.utils.Result;
import com.xll.utils.SecurityUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @Autowired
    private RemarkService remarkService;

    @Autowired
    private HotelService hotelService;
    @ApiOperation(value = "添加酒店信息")
    @PostMapping("/insert/{id}")
    public Result insertCell(@PathVariable Long id) {
        Hotel data = (Hotel) hotelService.findById(id).getData();
        Order order = new Order();
        order.setHotelName(data.getHotelName());
        order.setHotelId(id);
        order.setHotelPrice(data.getHotelPrice());
        order.setUserName(SecurityUtils.getUsername());
        order.setUserId(SecurityUtils.getUserId());
        return orderService.insert(order);
    }

    @ApiOperation(value = "获取当前用户的评价以及订单")
    @PostMapping("/detail/{id}")
    public Map getInfo(@PathVariable Long id) {
        String username = SecurityUtils.getUsername();
        Result byUserId = orderService.findByUserId(id);
        Result byCreateUser = remarkService.findByCreateUser(username);
        List<Order> data = (List<Order>) byUserId.getData();
        List<Remark> remarkList=(List<Remark>) byCreateUser.getData();
        Map<String, Object> objectObjectMap = new HashMap<>();
        objectObjectMap.put("order",data);
        objectObjectMap.put("remark",remarkList);
        return  objectObjectMap;
    }

    @PostMapping("/findPage")
    public Result findAllCell(@RequestBody QueryInfo queryInfo) {
        return orderService.findPage(queryInfo);
    }

}
